package djl;

import static org.junit.Assert.assertTrue;
import djl.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IScoreSnapshot;
import robocode.control.snapshot.ITurnSnapshot;

/**
 * Illustrates JUnit testing of Robocode robots. This test verifies if DaBeast rams the enemy at
 * least once.
 * 
 * @author David Joel Lazaro
 * 
 */
public class TestDaBeastRamming extends RobotTestBed {
  ITurnSnapshot lastTurnSnapshot;
  boolean ramming = false;

  /**
   * Specifies that Corners and DaBeast are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Corners,djl.DaBeast";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * Checks to see if DaBeast rams the Corners at least once.
   * 
   * @param event Details about the completed turn.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    int score = 0;
    lastTurnSnapshot = event.getTurnSnapshot();

    for (IScoreSnapshot damage : lastTurnSnapshot.getSortedTeamScores()) {
      // Gets the ramming damage score.
      score = (int) damage.getCurrentRammingDamageScore();
    }

    // Ramming becomes true when the score is greater than 0.
    if (score > 0) {
      ramming = true;
    }

  }

  /**
   * The actual test, which asserts that DaBeast rammed the enemy.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check Damage", ramming);
  }
}
